import { ThemeVarService } from '../../../../lib/abstract/style/theme_var/service'
import { ICON_IDS } from '../../../../lib/icons/types/constants'
import {
  BodyClasses,
  BUTTON_TEMPLATE_STYLES,
  PROJECT_PREFIX,
} from '../../../../types/constants'
import { StylesService } from '../../../../types/constants/styles'

export function styles(adControlName: string): string {
  const width = 'clamp(250px, 25vw, 300px)'
  const boxShadow = '0 2px 12px rgba(0,0,0,0.1)'

  return `
#${adControlName} {
  all: initial;
  position: fixed !important;
  bottom: 10px;
  right: 100px;
  min-width: 50px !important;
  max-width: ${width} !important;
  background: var(--${PROJECT_PREFIX}-theme-ad-bg) !important;
  color: var(--${PROJECT_PREFIX}-theme-ad-text) !important;
  box-shadow: ${boxShadow};
  border-radius: 8px;
  max-height: 40vh;
  z-index: 9999 !important;
  display: block;
  ${StylesService.getInstance().scroll.default}
  
  &:not(.collapsed) {
    &:has(.filters.${BodyClasses.IS_EMPTY}) {
      .content {
        margin-right: 28px;
      }
    }
  }

  .ad-btn button {
    background: var(--${PROJECT_PREFIX}-theme-ad-button-bg) !important;
    color: var(--${PROJECT_PREFIX}-theme-ad-button-text) !important;
    border-radius: 4px !important;
    text-align: center !important;
    white-space: nowrap !important;
    
    &.toggle-all {
      background: #3085d6 !important;
      color: #ffffff !important;
    }
    
    &:hover {
      background: #c51fc7 !important;
      color: #ffffff !important;
    }
  }
  
  &.collapsed {
    height: 40px;
    overflow: hidden; /* 隐藏溢出内容 */
  }
  
  .content {
    all: initial; /* 清除所有继承样式 */
    position: relative;
    box-sizing: content-box !important; /* 内容盒子 */
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    max-height: unset !important;
    margin-bottom: 10px;
    padding: 10px;
  }
  
  h3 {
    color: var(--${PROJECT_PREFIX}-theme-ad-text) !important;
    margin: 0;
    height: 20px !important;
    font-size: 16px !important;
    font-weight: normal !important;
    .ad-counter {
      color: var(--${PROJECT_PREFIX}-theme-ad-counter-text) !important;
    }
  }
  
  .toggle-panel {
    all: initial; /* 清除所有继承样式 */
    cursor: pointer;
    background: none !important;
    border: none !important;
    margin: auto 5px;
    font-size: 18px !important;
    position: absolute;
    right: 10px;
  }
  
  .close-btn {
    ${BUTTON_TEMPLATE_STYLES.closeHover}
  }
  
  &:has(.filters.${BodyClasses.IS_EMPTY}) {
    .search-container, .ad-btn {
      display: none !important;
    }
    
    .content {
      margin-bottom: 0 !important;
    }
  }
  
  .search-container {
    margin: 10px 20px !important;
  }
  
  .filters {
    margin-left: 10px;
    max-height: 25vh;
    overflow-y: auto;
    padding: 0 10px 10px 0;
    
    label {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 5px;
      cursor: pointer;
      color: var(${ThemeVarService.getInstance().default.text.secondary}) !important;
      
      &:hover {
        .copy-selector-btn {
          opacity: 1 !important;
        }
      }
      
      input {
        appearance: auto !important;
        outline: none !important;
        accent-color: #315efb !important;
      }
      
      /* 位置指示器 */
      .position-indicator {
        &[data-position^="top"] {
          color: #4CAF50 !important;
        }
        &[data-position^="middle"] { 
          color: #2196F3 !important;
        }
        &[data-position^="bottom"] { 
          color: #9C27B0 !important;
        }
      }
      
      /* 名称 */
      .filter-name:hover {
        color: #c51fc7 !important;
      }
      
      /* 复制按钮 */
      .copy-selector-btn {
        all: initial;
        opacity: 0;
        font-size: 13px !important;
        color: var(${ThemeVarService.getInstance().default.text.secondary}) !important;
        
        &::before {
          ${StylesService.getInstance().inlinePseudo.icon({ backgroundImageId: ICON_IDS.action.copy, display: 'inline-block' })}
          vertical-align: bottom !important;
        }
        
        &.copy-success {
          color: var(${ThemeVarService.getInstance().message.success.textPrimary}) !important;
        }
        
        &.copy-error {
          color: var(${ThemeVarService.getInstance().message.error.textPrimary}) !important;
        }
      }
    }
  }
  
  .ad-btn {
    margin: 10px;
    display: none;
    gap: 10px;
    justify-content: flex-end;
    
    .reset-default, .toggle-all, .cancel-toggle-all {
      padding: 5px;
      font-size: 14px !important;
      border: none !important;
      line-height: normal !important;
    }
  }
}
`
}
